A "For Each" loop is a "shortcut" for a For Loop.
It is only useful in arrays and it automatically goes all the way through an array.

Original Way
for(int i = 0; i < myList.length; i++)

For Each Loop
for( type of things in the array variable name : array name )

    • iterator is actually the value of the array, not the index value.


ex.
for( int iterator : myList )
for( Mii iterator : myMiis )

Example of a code using For Each:

public int countEvens (int[] nums)
{
   /*
    * Go through whole list
    * Check if the number is even
    * Add one to my counter
    */
   int count = 0
   for( int interator : nums)
   {
      if (interator % 2 == 0)
      count++;
   }
   return count;
}
NOTE: for each loops are rarely used